package com.itheima.article.controller;


import com.itheima.article.dto.ArticleInfoDto;
import com.itheima.article.pojo.ApArticle;
import com.itheima.article.service.ApArticleService;
import com.itheima.common.pojo.PageInfo;
import com.itheima.common.pojo.PageRequestDto;
import com.itheima.common.pojo.Result;
import com.itheima.core.controller.AbstractCoreController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
* <p>
* 文章信息表，存储已发布的文章 控制器</p>
* @author czh
* @since 2021-08-20
*/
@RestController
@RequestMapping("/apArticle")
public class ApArticleController extends AbstractCoreController<ApArticle> {

    private ApArticleService apArticleService;

    //注入
    @Autowired
    public ApArticleController(ApArticleService apArticleService) {
        super(apArticleService);
        this.apArticleService=apArticleService;
    }

    /**
     * 保存文章或者更新文章 用于远程调用
     * @param articleInfoDto
     * @return
     */
    @PostMapping("/articleInfo/save")
    public Result<ApArticle> save(@RequestBody ArticleInfoDto articleInfoDto){
        ApArticle apArticle = apArticleService.saveArticle(articleInfoDto);
        return Result.ok(apArticle);
    }

    /**
     * 文章列表分页查询
     */
    @PostMapping("/searchPage")
    public Result<PageInfo<ApArticle>> searchOrder(@RequestBody PageRequestDto<ApArticle> dto){
        PageInfo<ApArticle> pageInfo = apArticleService.searchOrder(dto);
        return Result.ok(pageInfo);
    }

    /**
     * 文章详情
     *  1.查询Article
     *  2.apArticleContent
     *  3.apArticleConfig
     */

    @GetMapping("/detail/{articleId}")
    public Result<ArticleInfoDto> detailByArticleId(@PathVariable(value = "articleId") Long id){
        //执行查询
        ArticleInfoDto dto = apArticleService.detailByArticleId(id);
        return Result.ok(dto);
    }


}

